package engine.graphics;

import engine.objects.*; 

import static org.lwjgl.opengl.GL11.*; 

public final class Renderer {

	public static void renderTexturedObject(TexturedObject b, int renderMode, Color4f color){
		if(!(b  == null)){
			if(color == null){
				if(b.isColored())
					color = b.getColor();
				else
					color = new Color4f(1.0f, 1.0f, 1.0f, 0.0f); 
			}
			glColor4f(color.getR(), color.getG(), color.getB(), color.getA());
			if(b.isTextured()){
				glEnable(GL_TEXTURE_2D);
			}else{
				glDisable(GL_TEXTURE_2D);
			}
			glBegin(renderMode);{
				for(int i=0; i<b.getVertices().length; i++){
					if(b.isTextured())
						glTexCoord2f(b.getTexCoords().getTexUV(i).getU(), b.getTexCoords().getTexUV(i).getV()); 
					glVertex2f(b.getVertices()[i].getX(), b.getVertices()[i].getY());
				}
			}
			glEnd(); 
		}
	}
	
	public static void renderTexturedObject(TexturedObject o){
		renderTexturedObject(o, GL_QUADS, null);
	}

	public static void renderTexturedObject(TexturedObject o, int renderMode) {
			renderTexturedObject(o, renderMode, null) ; 
	}
	
	
	public static void renderLine(Line line){
		if(!(line  == null)){
			glColor4f(0.3f, 0.3f, 0.3f, 1.0f); 
			glPushMatrix(); 
				glBegin(GL_LINE_LOOP); 
				glVertex2f(line.getX1(), line.getY1()); 
				glVertex2f(line.getX2(), line.getY2()); 
				glEnd(); 
			glPopMatrix();
		}
	}
}
